<template>
  <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="80px" class="demo-ruleForm">
    <el-form-item label="角色名称" prop="roleName">
      <el-input v-model="ruleForm.roleName" />
    </el-form-item>
    <el-form-item label="角色编码" prop="roleCode">
      <el-input v-model="ruleForm.roleCode" />
    </el-form-item>
    <el-form-item label="角色备注">
      <el-input v-model="ruleForm.remark" type="textarea" :rows="3" />
    </el-form-item>
  </el-form>
</template>

<script>
import { createRole } from '@/api/role'
export default {
  name: 'VueElementAdminCreate',

  data() {
    return {
      ruleForm: {
        roleName: '',
        roleCode: ''
      },
      rules: {
        roleName: [
          { required: true, message: '请输入角色名称', trigger: 'blur' }
        ],
        roleCode: [
          { required: true, message: '请输入角色编码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const _this = this
          createRole(this.ruleForm).then(res => {
            this.$message({
              message: res.message,
              type: 'success',
              onClose: () => {
                _this.$emit('success')
              }
            })
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
